package com.xuecheng.content.controller;

import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.content.common.util.UAASecurityUtil;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author dongliang
 */
@Slf4j
@RestController
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    //查询教师列表
    @GetMapping("courseTeacher/list/{courseBaseId}")
    List<CourseTeacherDTO> queryTeacherList(@PathVariable Long courseBaseId){
        //1获取令牌id
        Long companyId = UAASecurityUtil.getCompanyId();
        //2.调用service根据Id查询此课程
        List<CourseTeacherDTO> courseTeacherDTOList = courseTeacherService.queryTeacherList(companyId,courseBaseId);

        return courseTeacherDTOList;
    }


    /**
     * 创建或修改课程计划信息
     * @param dto 课程计划信息
     * @return TeachplanDTO 课程计划信息
     */
    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyTeachPlan(@RequestBody CourseTeacherDTO dto){
        //1获取令牌id
        Long companyId = UAASecurityUtil.getCompanyId();
        //2.调用service根据Id查询此课程
        CourseTeacherDTO courseTeacherDTO = courseTeacherService.createOrModifyTeachPlan(dto, companyId);

        return courseTeacherDTO;
    }

    @DeleteMapping("courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public void removeCourseTeacher(@PathVariable Long courseBaseId,@PathVariable Long courseTeacherId){
        //1获取令牌id
        Long companyId = UAASecurityUtil.getCompanyId();
        //2.调用service根据Id查询此课程
        courseTeacherService.removeCourseTeacher(companyId, courseBaseId,courseTeacherId);

    }
}
